/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.isd.inventario.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.Query;
import com.isd.global.dao.BaseDAO;
import com.isd.global.web.MailFactory;
import com.isd.inventario.modelo.RubroPK;
import com.isd.inventario.modelo.SubTipo;
import java.util.logging.Level;
import java.util.logging.Logger;


/**
 *
 * @author ctrosch
 */
@Stateless
@LocalBean
public class SubTipoDAO extends BaseDAO{
    
    public List<SubTipo> getLista(){
        
        try {
            Query q = (Query) getEntityManager().createQuery("SELECT object(o) FROM  SubTipo as o WHERE o.debaja = 'N'");
            return q.getResultList();
        }catch(Exception e){
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "getLista", e);
            return null;
        }
    }

    public List<SubTipo> getListaByTipo(String tippro){

        Map<String,String> filtro = new HashMap<String,String>();
        filtro.put("tipoProducto.tippro = ", "'"+tippro+"'");
        filtro.put("debaja = ", "'N'");

        try {
            String sQuery = "SELECT o FROM  SubTipo as o ";
            sQuery += generarStringFiltro(filtro,"o", true);
            sQuery += " ORDER BY o.descrp ASC";

            Query q = getEntityManager().createQuery(sQuery);
            return q.getResultList();
        }catch(Exception e){
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "getListaByTipo", e);
            return null;
        }

    }

    public List<SubTipo> getListaByItemCatalogo(String tippro){

        Map<String,String> filtro = new HashMap<String,String>();
        filtro.put("tipoProducto.tippro = ", "'"+tippro+"'");
        filtro.put("debaja = ", "'N'");
        filtro.put("debaja = ", "'N'");

        try {
            String sQuery = "SELECT o FROM  SubTipo as o ";
            sQuery += generarStringFiltro(filtro,"o", true);
            sQuery += " ORDER BY o.descrp ASC";

            Query q = getEntityManager().createQuery(sQuery);
            return q.getResultList();
        }catch(Exception e){
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "getListaByItemCatalogo", e);
            return null;
        }

    }

    public SubTipo getSubTipo(RubroPK id) {
        try {
            return getEntityManager().find(SubTipo.class,id);
        }catch (Exception e){
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "getSubTipo", e);
            return null;
        }
    }






    
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
 
}
